package com.bckj.freshnow.goods.service;

import com.bckj.freshnow.goods.entity.GoodsCategory;
import com.bckj.freshnow.goods.mapper.GoodsCategoryMapper;
import com.bckj.freshnow.goods.repo.GoodsCategoryRepository;
import com.bckj.freshnow.goods.convert.GoodsCategoryConvert;
import com.bckj.freshnow.goods.model.GoodsCategoryResponse;
import com.bckj.freshnow.goods.model.GoodsCategoryRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品分类表(GoodsCategory)service
 *
 * @author makejava
 * @since 2025-04-21 16:22:23
 */
@Service
@RequiredArgsConstructor
public class GoodsCategoryService {

    private final GoodsCategoryRepository goodsCategoryRepository;
    private final GoodsCategoryMapper goodsCategoryMapper;
    private final GoodsCategoryConvert goodsCategoryConvert;
	
    /**
     * 列表
     *
     * @param request req
     * @return list
     */
    public List<GoodsCategoryResponse> findAll(GoodsCategoryRequest request){
        return goodsCategoryMapper.findAll(request);
    }
    
    /**
     * 详情
     *
     * @param id id
     * @return vo
     */
    public GoodsCategoryResponse details(Long id) {
        GoodsCategory entity = goodsCategoryRepository.getById(id);
        return goodsCategoryConvert.bean2Response(entity);
    }
    
    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public boolean saveGoodsCategory(GoodsCategoryRequest request) {
        GoodsCategory data = goodsCategoryConvert.request2Bean(request);
        return goodsCategoryRepository.save(data);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean updateGoodsCategory(GoodsCategoryRequest request) {
        GoodsCategory data = goodsCategoryConvert.request2Bean(request);
        return goodsCategoryRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
		return goodsCategoryRepository.removeById(id);
	}
}

